﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Groovy_IM.Assets;

namespace Groovy_IM
{
    public partial class JoinChatPage : PhoneApplicationPage
    {
        private int selAcc;

        public JoinChatPage()
        {
            InitializeComponent();

            accs.DataContext = App.Accounts;
        }

        private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {

        }

        private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string sTag;

            if ((sender as TextBlock) != null)
                sTag = (sender as TextBlock).Tag.ToString();
            else
                sTag = (sender as Image).Tag.ToString();

            selAcc = Convert.ToInt32(sTag);

            accs.SelectedIndex = -1;

            for (int i = 0; App.Accounts.Items.Count > i; i++)
            {
                App.Accounts.Items[i].Selected = new Uri("Images/Protocols/nonselected.png", UriKind.Relative);
                App.Accounts.Items[i].pSelected = 0;
            }

            App.Accounts.Items[selAcc].Selected = new Uri("Images/Protocols/Checkmark.png", UriKind.Relative);
            App.Accounts.Items[selAcc].pSelected = 1;
        }

        private void btnJoin_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; App.Accounts.Items.Count > i; i++)
            {
                App.Accounts.Items[i].Selected = new Uri("Images/Protocols/nonselected.png", UriKind.Relative);
                App.Accounts.Items[i].pSelected = 0;
            }

            App.m_Actions.JoinChat(selAcc, Room.Text, Exchange.Text, Type.Text, "", "");

            NavigationService.GoBack();
        }
    }
}